package simple;

import org.nutz.dao.Dao;
import org.nutz.dao.util.Daos;
import org.nutz.ioc.Ioc;
import org.nutz.mvc.NutConfig;
import org.nutz.mvc.Setup;
import simple.entity.*;
import simple.logic.UserLogic;
import simple.utils.IocUtil;

public class AppSetup implements Setup {


    @Override
    public void init(NutConfig conf) {
        IocUtil.init(conf);
        Ioc ioc = conf.getIoc();
        Dao dao = IocUtil.get(Dao.class);
        UserLogic userLogic = IocUtil.get(UserLogic.class);
        Daos.createTablesInPackage(dao, "simple.entity", false);
        Daos.migration(dao, "simple.entity", true, true);
        // 初始化默认根用户
        if (dao.count(UserEntity.class) == 0) {
            UserEntity user = new UserEntity("admin","admin","管理员","123456");
            userLogic.insert(user);
        }
    }

    @Override
    public void destroy(NutConfig conf) {
    }

}
